import org.junit.Test;

/**
 * @author 张心宇 <zhangxinyu20@kuaishou.com>
 * Created on 2022-12-16
 */
public class M62UniquePaths {
    public int uniquePaths(int m, int n) {
        if(m == 1 || n== 1){
            return 1;
        }
        return uniquePaths(m-1, n) + uniquePaths(m, n-1);
    }

    public int uniquePathsDP(int m, int n) {
        int[][] dp = new int[m+1][n+1];

        // base case
        for (int i = 0; i <= m; i++) {
            dp[i][1] = 1;
        }
        for (int j = 0; j<=n; j++){
            dp[1][j] = 1;
        }
        for (int i =2; i<=m; i++){
            for (int j=2; j<=n; j++){
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
            }
        }
        return dp[m][n];
    }



    @Test
    public void test(){
        System.out.println(uniquePathsDP(3,3));
    }

}
